﻿using System;
using System.Collections.Generic;
using ContractManager.Entity;
using Speed.Data;

namespace ContractManager.BLL.Business
{
    public static class ClsDepartments
    {
        public static List<Departments> SelectAll()
        {
            using (var db = Sys.NewDb())
            {
                return Data.Base.Departments.Select(db);
            }
            
        }

        public static void Insert(Departments capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Insert<Departments>(capital, EnumSaveMode.Requery);
            }
           
        }

        public static void Update(Departments capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Update<Departments>(capital);
            }
            
        }

        public static Departments SelectByPk(Int32 depId)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<Departments>(string.Format("ID={0}", depId));
            }
            
        }

        public static Departments SelectByCode(string depCode)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<Departments>(string.Format("Code='{0}'", depCode));
            }
            
        }

        public static int DeleteByPk(Int32 depId)
        {
            using (var db = Sys.NewDb())
            {
                return db.Delete<Departments>(string.Format("ID={0}", depId));
            }
            
        }
    }
}
